//
//  MainGameUI.m
//  ProjectL
//
//  Created by Nguyen Tan Loc on 9/5/13.
//  Copyright (c) 2013 Nguyen Tan Loc. All rights reserved.
//

#import "MainGameUI.h"
#import "LevelManager.h"
#import "LevelChoosingScene.h"
#import "ItemPopup.h"
#import "ItemIcon.h"
#import "Setting.h"
#import "CalibratePopup.h"
#import "MainGameScene.h"
#import "Utility.h"

@implementation MainGameUI

@synthesize _levelTimeShow = mLevelTimeShow;
@synthesize _miItemGlove = mMIItemGlove;
@synthesize _miItemMagnet = mMIItemMagnet;
@synthesize _miItemTimer = mMIItemTimer;
@synthesize _miItemXray = mMIItemXRay;
@synthesize _menuType = mMenuType;

-(id) init
{
    if (self = [super initWithColor:ccc4(0, 0, 0, 0)])
    {
        mMenuType = eMT_HIDE;
        [self initTwoLine];
        [self initTime];
        [self initEnergy];
        [self initMenu];
        [self initLabelLevel];
        [self updateItemInfo];
        
        self.touchEnabled = YES;
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateItemInfo) name:EVENT_ITEM_CHANGED object:nil];
    }
    
    return self;
}

-(void) registerWithTouchDispatcher
{
    [[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:TOUCH_PRIORITY_MAIN_UI swallowsTouches:YES];
}

-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{

    return NO;
}

-(void) initTwoLine
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    
    CCSprite *sprB1 = [CCSprite spriteWithSpriteFrameName:SFN_BLACK_BAND];
    [sprB1 setAnchorPoint:ccp(0, 0)];
    [sprB1 setScaleX:(winSize.width / sprB1.contentSize.width)];
    [sprB1 setScaleY:(uniPos(40, 80) / sprB1.contentSize.height)];
    [sprB1 setPosition:ccp(0, 0)];
    [self addChild:sprB1 z:-1000];
    
    CCSprite *sprB2 = [CCSprite spriteWithSpriteFrameName:SFN_BLACK_BAND];
    [sprB2 setAnchorPoint:ccp(0, 1)];
    [sprB2 setScaleY:(uniPos(40, 80) / sprB1.contentSize.height)];
    [sprB2 setScaleX:(winSize.width / sprB2.contentSize.width)];
    [sprB2 setPosition:ccp(0, winSize.height)];
    [self addChild:sprB2 z:-1000];
    
    
    CCSprite *spr = [CCSprite spriteWithSpriteFrameName:SFN_THICK_LINE];
    [spr setPosition:uniPos(ccp(winSize.width / 2, 40), ccp(winSize.width / 2, 80))];
    [self addChild:spr];
    
    CCSprite *spr2 = [CCSprite spriteWithSpriteFrameName:SFN_THICK_LINE];
    [spr2 setPosition:uniPos(ccp(winSize.width / 2, winSize.height - 40), ccp(winSize.width / 2, winSize.height - 80))];
    [self addChild:spr2];

}

-(void) initMenu
{
    int es = IS_IPHONE ? 10 : 20;
    // pause
    mMIPause = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:SFN_ICON_PAUSE]
                                       selectedSprite:[CCSprite spriteWithSpriteFrameName:SFN_ICON_PAUSE]
                                               target:self
                                             selector:@selector(onPause)];
    [mMIPause setActiveArea:CGRectMake(-es, -es, mMIPause.contentSize.width + es * 2, mMIPause.contentSize.height + es * 2)];
    
    // resume
    mMIResume = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:SFN_ICON_RESUME]
                                        selectedSprite:nil
                                                target:self
                                              selector:@selector(onResume)];
    [mMIResume setActiveArea:CGRectMake(-es, -es, mMIPause.contentSize.width + es * 2, mMIPause.contentSize.height + es * 2)];
    
    // replay
    mMIReplay = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:SFN_ICON_REPLAY_2]
                                        selectedSprite:nil
                                                target:self
                                              selector:@selector(onReplay)];
    [mMIReplay setActiveArea:CGRectMake(-es, -es, mMIReplay.contentSize.width + es * 2, mMIReplay.contentSize.height + es * 2)];
    
    // calibrate
    mMICalibrate = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:SFN_ICON_CALIBRATE]
                                        selectedSprite:nil
                                                target:self
                                              selector:@selector(onCalibrate)];
    [mMICalibrate setActiveArea:CGRectMake(-es, -es, mMIPause.contentSize.width + es * 2, mMIPause.contentSize.height + es * 2)];
    
    // music
    CCSprite *sprBtnMusicOn = [CCSprite spriteWithSpriteFrameName:SFN_BTN_MUSIC_ON];
    CCSprite *sprBtnMusicOnHover = [CCSprite spriteWithSpriteFrameName:SFN_BTN_MUSIC_ON];
    [sprBtnMusicOnHover setColor:CL_BTN_MUSIC];
    
    CCSprite *sprBtnMusicOff = [CCSprite spriteWithSpriteFrameName:SFN_BTN_MUSIC_OFF];
    CCSprite *sprBtnMusicOffHover = [CCSprite spriteWithSpriteFrameName:SFN_BTN_MUSIC_OFF];
    [sprBtnMusicOffHover setColor:CL_BTN_MUSIC];
    CCMenuItem *mMIMusicOn = [CCMenuItemSprite itemWithNormalSprite:sprBtnMusicOn
                                                     selectedSprite:sprBtnMusicOnHover];
    CCMenuItem *mMIMusicOff = [CCMenuItemSprite itemWithNormalSprite:sprBtnMusicOff
                                                      selectedSprite:sprBtnMusicOffHover];
    
    mMIMusicOn.tag = 1;
    mMIMusicOff.tag = 0;
    mMISoundBG = [CCMenuItemToggle itemWithTarget:self selector:@selector(onSoundBG:) items:mMIMusicOn, mMIMusicOff, nil];
    if (![Setting getInstance]._isSoundBG)
        mMISoundBG.selectedIndex = 1;
    
    [mMISoundBG setActiveArea:CGRectMake(-es, -es, mMIPause.contentSize.width + es * 2, mMIPause.contentSize.height + es * 2)];
    
    // sound effect
    CCSprite *sprBtnSoundOn = [CCSprite spriteWithSpriteFrameName:SFN_BTN_SOUND_ON];
    CCSprite *sprBtnSoundOnHover = [CCSprite spriteWithSpriteFrameName:SFN_BTN_SOUND_ON];
    [sprBtnSoundOnHover setColor:CL_BTN_SOUND];
    
    CCSprite *sprBtnSoundOff = [CCSprite spriteWithSpriteFrameName:SFN_BTN_SOUND_OFF];
    CCSprite *sprBtnSoundOffHover = [CCSprite spriteWithSpriteFrameName:SFN_BTN_SOUND_OFF];
    [sprBtnSoundOffHover setColor:CL_BTN_SOUND];
    CCMenuItem *mMISoundOn = [CCMenuItemSprite itemWithNormalSprite:sprBtnSoundOn
                                                     selectedSprite:sprBtnSoundOnHover];
    CCMenuItem *mMISoundOff = [CCMenuItemSprite itemWithNormalSprite:sprBtnSoundOff
                                                      selectedSprite:sprBtnSoundOffHover];
    
    mMISoundOn.tag = 1;
    mMISoundOff.tag = 0;
    mMISoundFX = [CCMenuItemToggle itemWithTarget:self selector:@selector(onSoundFX:) items:mMISoundOn, mMISoundOff, nil];
    if (![Setting getInstance]._isSoundFX)
        mMISoundFX.selectedIndex = 1;
    [mMISoundOff setActiveArea:CGRectMake(-es, -es, mMIPause.contentSize.width + es * 2, mMIPause.contentSize.height + es * 2)];
    
    // main home
    mMIMainMenu = [CCMenuItemSprite itemWithNormalSprite:[CCSprite spriteWithSpriteFrameName:SFN_BTN_MAIN_MENU]
                                        selectedSprite:nil
                                                target:self
                                              selector:@selector(onMainMenu)];
    [mMIMainMenu setActiveArea:CGRectMake(-es, -es, mMIPause.contentSize.width + es * 2, mMIPause.contentSize.height + es * 2)];
    
    // item glove
    mMIItemGlove = [[[ItemIcon alloc] initWithType:eIT_SHIELD] autorelease];
    
    mMIItemXRay = [[[ItemIcon alloc] initWithType:eIT_XRAY] autorelease];
    
    mMIItemTimer = [[[ItemIcon alloc] initWithType:eIT_TIMER] autorelease];
    
    mMIItemMagnet = [[[ItemIcon alloc] initWithType:eIT_MAGNET] autorelease];
    
    mLayerAlpha = [[[CCLayerColor alloc] initWithColor:ccc4(0, 0, 0, 0)] autorelease];
    [mLayerAlpha setVisible:NO];
    
    
    mMenuIcon = [[[CCMenu alloc] init] autorelease];
    [mMenuIcon setTouchPriority:TOUCH_PRIORITY_MAIN_UI];
    [mMenuIcon setPosition:CGPointZero];
    
    mMenuItem = [[[CCMenu alloc] init] autorelease];
    [mMenuItem setTouchPriority:TOUCH_PRIORITY_MAIN_UI];
    [mMenuItem setPosition:CGPointZero];
    
    [self addChild:mMenuItem z:-1];
    [self addChild:mLayerAlpha z:0];
    [self addChild:mMenuIcon z:1];
    
    [mMenuIcon addChild:mMIPause z:0 tag:0];
    [mMenuIcon addChild:mMIResume z:5 tag:1];
    [mMenuIcon addChild:mMIReplay z:5 tag:2];
    [mMenuIcon addChild:mMICalibrate z:5 tag:3];
    [mMenuIcon addChild:mMISoundBG z:5 tag:4];
    [mMenuIcon addChild:mMISoundFX z:5 tag:5];
    [mMenuIcon addChild:mMIMainMenu z:5 tag:6];
    
    [mMenuItem addChild:mMIItemGlove z:0 tag:10];
    [mMenuItem addChild:mMIItemXRay z:0 tag:11];
    [mMenuItem addChild:mMIItemTimer z:0 tag:12];
    [mMenuItem addChild:mMIItemMagnet z:0 tag:13];
    
    
    for (int i = 0; i < 6; i++)
    {
        CCLabelBMFont *lb = [CCLabelBMFont labelWithString:@"" fntFile:FONT_DEFAULT];
        [lb setAnchorPoint:ccp(1, 0.5f)];
        [lb setOpacity:0];
        [self addChild:lb z:1 tag:(TAG_LABEL_ICON_MENU + i)];
    }
    [self updateLabelMenu];
    
    [self arrangeMenu];
    mMenuType = eMT_HIDE;
}

-(void) arrangeMenu
{
    // arrange menu
    CCMenuItem *pause = (CCMenuItem *)[mMenuIcon getChildByTag:0];
    [pause setPosition:[self getIconLocation:0 isShow:YES]];
    
    
    for (int i = 1; i <= 6; i++)
    {
        CCMenuItem *menuItem = (CCMenuItem *)[mMenuIcon getChildByTag:i];
        [menuItem setPosition:[self getIconLocation:i isShow:NO]];
        [menuItem setIsEnabled:NO];
        
        CCNode *label = [self getChildByTag:(TAG_LABEL_ICON_MENU + i - 1)];
        [label setPosition:uniPos(ccp(menuItem.position.x - 80, menuItem.position.y), ccp(menuItem.position.x - 160, menuItem.position.y))];
    }
}

-(void) checkAvailableItem
{
    int tag = 10;
    for (int i = 0; i < 4; i++)
    {
        ItemIcon *menuItem = (ItemIcon *)[mMenuItem getChildByTag:tag];
        [menuItem setNumItemUse:0];
        
        if (![[LevelManager getInstance] isItemAvailable:(ITEM_TYPE)i])
        {
            [menuItem setIsEnabled:NO];
            [menuItem setOpacity:50];
        }
        else
        {
            [menuItem setIsEnabled:YES];
            [menuItem setOpacity:255];
        }
        
        tag++;
    }
    
    // arrange item
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    int anchor = 4;
    
    if (anchor > 0)
    {
        float anchorX = (winSize.width - 20) / (anchor);
        int count = 1;
        int paddleX = uniPos(-40, -80);
        int baseY = 22;
        float baseX;
        for (int i = 10; i <= 14; i++)
        {
//            if (![[LevelManager getInstance] isItemAvailable:(ITEM_TYPE)(count - 1)])
//                continue;
            
            baseX = count * anchorX + paddleX;
            CCMenuItem *menuItem = (CCMenuItem *)[mMenuItem getChildByTag:i];
            [menuItem setPosition:uniPos(ccp(baseX, baseY), ccp(baseX, baseY * 2))];
            
            count++;
        }
    }
}

-(CGPoint) getIconLocation:(int)index isShow:(BOOL)isShow
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    float startX = isShow ? winSize.width - uniPos(20, 40) : winSize.width + uniPos(20, 40);
    float startY = winSize.height - uniPos(20, 40);
    float paddle = uniPos(50, 100);
    
    return uniPos(ccp(startX, startY - index * paddle), ccp(startX, (startY - index * paddle)));
}

-(void) onPause
{
    if ([MainGameScene getInstance]._mainGameState == sMG_ENDING)
        return;
    CCLOG(@"pause");
    
    if (mMenuType == eMT_TRANSITING)
        return;

    [[Utility getInstance] playEffect:SOUND_MENU_OPEN];
    if (mMenuType == eMT_HIDE)
    {
        for (int i = 1; i <= 6; i++)
        {
            CCDelayTime *delay = [CCDelayTime actionWithDuration:0.05 * i];
            CCMoveTo *moveTo = [CCMoveTo actionWithDuration:0.3 position:[self getIconLocation:i isShow:YES]];
            CCEaseBackOut *easeOut = [CCEaseBackOut actionWithAction:moveTo];
            CCSequence *sequence;
            CCMenuItem *menuItem;
            
            if (i == 6)
            {
                CCCallBlock *callBlock = [CCCallBlock actionWithBlock:^{
                    mMenuType = eMT_SHOW;
                }];
                sequence = [CCSequence actions:delay, easeOut, callBlock, nil];
            }
            else
            {
                sequence = [CCSequence actions:delay, easeOut, nil];
            }
            
            menuItem = (CCMenuItem *)[mMenuIcon getChildByTag:i];
            [menuItem runAction:sequence];
            [menuItem setIsEnabled:YES];
            
            CCDelayTime *delay2 = [CCDelayTime actionWithDuration:0.05 * i];
            CCFadeTo *fadeTo2 = [CCFadeTo actionWithDuration:0.3 opacity:255];
            CCSequence *sequence2 = [CCSequence actions:delay2, fadeTo2, nil];
            CCNode *lb = [self getChildByTag:(TAG_LABEL_ICON_MENU - 1 + i)];
            [lb runAction:sequence2];
        }
        
        CCFadeTo *fadeTo = [CCFadeTo actionWithDuration:0.4 opacity:200];
        [mLayerAlpha runAction:fadeTo];
        [mLayerAlpha setVisible:YES];
        [mMenuItem setEnabled:NO];
        [[MainGameScene getInstance] pause];
    }
    else if (mMenuType == eMT_SHOW)
    {
        for (int i = 1; i <= 6; i++)
        {
            CCDelayTime *delay = [CCDelayTime actionWithDuration:0.05 * (6 - i)];
            CCMoveTo *moveTo = [CCMoveTo actionWithDuration:0.3 position:[self getIconLocation:i isShow:NO]];
            CCEaseBackOut *easeOut = [CCEaseBackIn actionWithAction:moveTo];
            CCSequence *sequence;
            CCMenuItem *menuItem;
            
            if (i == 1)
            {
                CCCallBlock *callBlock = [CCCallBlock actionWithBlock:^{
                    mMenuType = eMT_HIDE;
                }];
                sequence = [CCSequence actions:delay, easeOut, callBlock, nil];
            }
            else
            {
                sequence = [CCSequence actions:delay, easeOut, nil];
            }
            
            menuItem = (CCMenuItem *)[mMenuIcon getChildByTag:i];
            [menuItem runAction:sequence];
            [menuItem setIsEnabled:NO];
            
            CCDelayTime *delay2 = [CCDelayTime actionWithDuration:0.05 * (6 - i)];
            CCFadeTo *fadeTo2 = [CCFadeTo actionWithDuration:0.3 opacity:0];
            CCSequence *sequence2 = [CCSequence actions:delay2, fadeTo2, nil];
            CCNode *lb = [self getChildByTag:(TAG_LABEL_ICON_MENU - 1 + i)];
            [lb runAction:sequence2];

        }
        
        CCFadeTo *fadeTo = [CCFadeTo actionWithDuration:0.4 opacity:0];
        CCCallBlock *callBlock = [CCCallBlock actionWithBlock:^{
            [mLayerAlpha setVisible:NO];
            [mMenuItem setEnabled:YES];
            [[MainGameScene getInstance] resume];
        }];
        CCSequence *sequence = [CCSequence actions:fadeTo, callBlock, nil];
        [mLayerAlpha runAction:sequence];
    }
    
    mMenuType = eMT_TRANSITING;
}

-(void) onResume
{
    CCLOG(@"resume");
    [[Utility getInstance] playEffect:SOUND_MENU_BUTTON];
    [self onPause];
}

-(void) onReplay
{
    [[Utility getInstance] playEffect:SOUND_MENU_BUTTON];
    [[MainGameScene getInstance] replay];
    [self onPause];
}

-(void) onCalibrate
{
    [[Utility getInstance] playEffect:SOUND_MENU_BUTTON];
    CalibratePopup *popup = [CalibratePopup node];
    [[CCDirector sharedDirector].runningScene addChild:popup z:Z_RESULT_POPUP];
}

-(void) onSoundBG:(id)sender
{
    [[Utility getInstance] playEffect:SOUND_MENU_BUTTON];
    CCLOG(@"sound background");
    CCMenuItemToggle *item = (CCMenuItemToggle *)(sender);
    if (item.selectedItem.tag == 1)
    {
        [Setting getInstance]._isSoundBG = YES;
    }
    else
    {
        [Setting getInstance]._isSoundBG = NO;
    }
    [self updateLabelMenu];
}

-(void) onSoundFX:(id)sender
{
    
    [[Utility getInstance] playEffect:SOUND_MENU_BUTTON];
    CCLOG(@"sound fx");
    CCMenuItemToggle *item = (CCMenuItemToggle *)(sender);
    if (item.selectedItem.tag == 1)
    {
        [Setting getInstance]._isSoundFX = YES;
    }
    else
    {
        [Setting getInstance]._isSoundFX = NO;
    }
    [self updateLabelMenu];
}

-(void) onMainMenu
{
    [[Utility getInstance] playEffect:SOUND_MENU_BUTTON];
    
    CCLOG(@"main menu");
//    [[CCDirector sharedDirector] replaceScene:[LevelChoosingScene scene]];
    [[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:0.5 scene:[LevelChoosingScene scene]]];
}

-(void) initEnergy
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    
    mIconEnergy = [CCSprite spriteWithSpriteFrameName:SFN_ICON_ENERGY];
    [mIconEnergy setPosition:uniPos(ccp(winSize.width / 2 - mIconEnergy.contentSize.width / 2, winSize.height - 20), ccp(winSize.width / 2, winSize.height - 40))];
    [self addChild:mIconEnergy];
    
    mLabelEnergy = [[CCLabelBMFont alloc] initWithString:@"" fntFile:FONT_NUMBER];
    [mLabelEnergy setAnchorPoint:ccp(0, 0.5)];
    [mLabelEnergy setPosition:ccp(mIconEnergy.position.x + uniPos(15, 30), mIconEnergy.position.y)];
    [self addChild:mLabelEnergy];
    [mLabelEnergy release];
}

-(void) initTime
{
    CGSize winSize = [[CCDirector sharedDirector] winSize];
    
    mIconTime = [CCSprite spriteWithSpriteFrameName:SFN_ICON_CLOCK];
    [mIconTime setPosition:uniPos(ccp(20, winSize.height - 20), ccp(40, winSize.height - 40))];
    [self addChild:mIconTime];
    
    mLabelTime = [[CCLabelBMFont alloc] initWithString:@"" fntFile:FONT_NUMBER];
    [mLabelTime setAnchorPoint:ccp(0, 0.5)];
    [mLabelTime setPosition:ccp(mIconTime.position.x + uniPos(15, 30), mIconTime.position.y)];
    [self addChild:mLabelTime];
    [mLabelTime release];
}

-(void) updateTime
{
    NSString *strTime = [NSString stringWithFormat:@"%.1f", [LevelManager getInstance]._levelTime];
    [mLabelTime setString:strTime];
}

-(void) updateTimeNextTime
{
    [self unschedule:@selector(updateTimeAnim:)];
    [self schedule:@selector(updateTimeAnim:)];
}

-(void) updateTimeAnim:(ccTime)delta
{
    mLevelTimeShow += ITEM_TIMER_PLUS_SPEED * delta;
    if (mLevelTimeShow >= [LevelManager getInstance]._levelTime)
    {
        mLevelTimeShow = [LevelManager getInstance]._levelTime;
        [self unschedule:_cmd];
    }
    
    NSString *strTime = [NSString stringWithFormat:@"%.1f", mLevelTimeShow];
    [mLabelTime setString:strTime];
}

-(void) updateEnergy
{
    NSString *strEnergy = [NSString stringWithFormat:@"%d/%d", [LevelManager getInstance]._numEnergy, [LevelManager getInstance]._maxNumEnergy];
    [mLabelEnergy setString:strEnergy];
}

-(void) initLabelLevel
{
    mLabelLevel = [[CCLabelBMFont alloc] initWithString:@"1231231" fntFile:FONT_DEFAULT];
    [mLabelLevel setAnchorPoint:ccp(0, 0)];
    [mLabelLevel setPosition:uniPos(ccp(5, 45), ccp(20, 100))];
    [mLabelLevel setOpacity:128];
    [self addChild:mLabelLevel z:-100];
    [mLabelLevel release];
}

-(void) updateLabelLevel
{
    [mLabelLevel setString:[NSString stringWithFormat:@"Level %d", [LevelManager getInstance]._currentLevel + 1]];
}

-(void) checkAvailableUI
{
    BOOL isTimeVisible = ([LevelManager getInstance]._levelTime > 0);
    [mIconTime setVisible:isTimeVisible];
    [mLabelTime setVisible:isTimeVisible];
    
    BOOL isEnergyVisible = ([LevelManager getInstance]._maxNumEnergy > 0);
    [mIconEnergy setVisible:isEnergyVisible];
    [mLabelEnergy setVisible:isEnergyVisible];
}

-(void) showItem:(BOOL)isShow
{
//    int opacity = isShow ? 255 : 0;
//    for (int i = 5; i <= 8; i++)
//    {
//        CCMenuItem *menuItem = (CCMenuItem *)[mMenuIcon getChildByTag:i];
//        CCFadeTo *fadeTo = [CCFadeTo actionWithDuration:0.5 opacity:opacity];
//        [menuItem stopAllActions];
//        [menuItem runAction:fadeTo];
//    }
}

-(CGPoint) getIconEnergyPosition
{
    return mIconEnergy.position;
}

-(void) updateItemInfo
{
    [mMIItemGlove updateLabel];
    [mMIItemMagnet updateLabel];
    [mMIItemTimer updateLabel];
    [mMIItemXRay updateLabel];
}

-(ItemIcon *) getItemIconWithType:(ITEM_TYPE)type
{
    switch (type) {
        case eIT_SHIELD:
            return mMIItemGlove;
            
        case eIT_MAGNET:
            return mMIItemMagnet;
            
        case eIT_TIMER:
            return mMIItemTimer;
            
        case eIT_XRAY:
            return mMIItemXRay;
        default:
            return nil;
    }
}

-(NSString *) getIconMenuText:(int)index;
{
    switch (index) {
        case 0:
            return @"Resume";
            
        case 1:
            return @"Replay";
            
        case 2:
            return @"Calibrate";
            
        case 3:
            if ([Setting getInstance]._isSoundBG)
                return @"Music: on";
            else
                return @"Music: off";
            
        case 4:
            if ([Setting getInstance]._isSoundFX)
                return @"Sound: on";
            else
                return @"Sound: off";
            
        case 5:
            return @"Main menu";
            
        default:
            return @"";
    }
}

-(void) updateLabelMenu
{
    for (int i = 0; i < 6; i++)
    {
        CCLabelBMFont *lb = (CCLabelBMFont *)[self getChildByTag:(TAG_LABEL_ICON_MENU + i)];
        [lb setString:[self getIconMenuText:i]];
    }
}


-(void) dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
    CCLOG(@"MainGameUI dealloc!");
}

@end